namespace OpenComposite.EII.Repository
{
	using System;
	using System.Collections.Generic;
	using System.Drawing;
	using System.Text;

	using OpenComposite.Repository.Properties;

	[RepositoryItem(ItemType.Diagram, "repository_diagrams", "diagram_id")]
	public class Diagram : RepositoryItemBaseEx
	{
		#region Initialization

		public Diagram()
			: base("diagram_id", "diagram_nm", "diagram_desc", "diagram_ntext", Resources.sNewDiagram)
		{
		}

		public Diagram(bool bCreateNew)
			: this()
		{
			if ( bCreateNew )
				this.CreateNew();
		}

		public Diagram(int id)
			: this()
		{
			this.Load(id);
		}

		#endregion Initialization

		#region Public Members

		#region Properties

		public override List<ItemType> AllowedChildTypes
		{
			get { return _LISTALLOWED; }
		}

		public override Image Image
		{
			get
			{
				switch ( this.Type ) {
					case ItemType.BRule:
						return Resources.png_brule;
					default:
						return Resources.diagram;
				}
			}
		}

		public override string ImageKey
		{
			get
			{
				switch ( this.Type ) {
					case ItemType.BRule:
						return "brule";
					default:
						return "diagram";
				}
			}
		}

		public override ItemType RepositoryItemType
		{
			get { return ItemType.Diagram; }
		}

		public override string RepositoryItemTypeDescription
		{
			get { return ""; }
		}

		public override string RepositoryItemTypeName
		{
			get { return Resources.sDiagram; }
		}

		public override Image SelectedImage
		{
			get { return this.Image; }
		}

		public override string SelectedImageKey
		{
			get { return this.ImageKey; }
		}

		public override string TableName
		{
			get { return "repository_diagrams"; }
		}

		public ItemType Type
		{
			get { return (ItemType)getValue("diagram_type", ItemType.Diagram); }
			set { setValue("Type", "diagram_type", value); }
		}

		#endregion Properties

		#region Methods

		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep"><c>true</c> to recursively copy the item and all subitems;
		/// <c>false</c> to copy only the item itself.</param>
		/// <returns>The copied item.</returns>
		public override IRepositoryItem Copy(bool deep)
		{
			Diagram copy = new Diagram(true);
			copy.InitializeServiceProvider(this);
			this.CopyDataRowToTarget(copy);
			return copy;
		}

		/// <summary>
		/// Gets the icon.
		/// </summary>
		/// <returns></returns>
		public override Icon GetIcon()
		{
			Bitmap bmp = new Bitmap(this.Image);
			bmp.MakeTransparent(Color.Magenta);
			return Icon.FromHandle(bmp.GetHicon());
		}

		#endregion Methods

		#endregion Public Members

		#region Internal Members

		#region Constant/Read-Only Fields

		internal const string ColumnDescription = "diagram_desc";
		internal const string ColumnID = "diagram_id";
		internal const string ColumnNText = "diagram_ntext";
		internal const string ColumnName = "diagram_nm";

		#endregion Constant/Read-Only Fields

		#endregion Internal Members

		#region Private Members

		#region Static Fields

		private static List<ItemType> _LISTALLOWED = new List<ItemType>(new ItemType[] {
					ItemType.GenericFolder, ItemType.Undefined });

		#endregion Static Fields

		#endregion Private Members
	}
}